//
// Created by 11510 on 2025/10/2.
//

#include "ManCommand.h"

xclib_client::ManCommand::ManCommand(CommandContext ctx) : ICommand("man", ctx) {};

std::optional<std::future<int>> xclib_client::ManCommand::run(const std::vector<std::string> &args, bool wait) {
    if (args.size() < 2) {
        std::cout << "man requires a command name\n";
        return std::nullopt;
    }
    std::string cmd = args[1];
    if (!CommandFactory::instance().has(cmd)) {
        std::cout << "No manual entry for '" << cmd << "'\n";
        return std::nullopt;
    }
    auto c = CommandFactory::instance().create(cmd, ctx);
    std::cout << c->longHelp() << "\n";
    return std::nullopt;
}

std::string xclib_client::ManCommand::shortHelp() const { return "man <command>"; }

std::string xclib_client::ManCommand::longHelp() const { return "man <command>\n    show detailed help for a command"; }